<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>

  还剩<span id="day">xx</span>天：<sapn id="hour">xx</sapn>时：<span id="minutes">x</span>分：<span id="second">xx</span>秒
  <script>

var day=document.getElementById('day')
var hour=document.getElementById('hour')
var minutes=document.getElementById('minutes')
var second=document.getElementById('second')

var targetTime=+new Date('2022-5-1 0:0:0');
getTime()
setInterval(getTime,1000)
function getTime(){
  var nowTime=+new Date();
// 毫秒换算成秒
var time=(targetTime-nowTime)/1000;
var d=parseInt(time/60/60/24)
day.innerHTML=d
var h=parseInt(time/60/60%24)
h<10?"0"+h:h
hour.innerHTML=h
var m=parseInt(time/60%60)
m<10?"0"+m:m
minutes.innerHTML=m
var s=parseInt(time%60)
s<10?"0"+s:s
  second.innerHTML=s
}

  </script>
</body>
</html>